package model

import (
	"manager/model/entity"
	"manager/utils"
)

// TableLogCreateRequest 创建现场数据
type TableLogCreateRequest struct {
	OperatorId int64 `json:"operator_id"`

	Type int `json:"type"`

	TableName string `json:"table_name"`

	Comment string `json:"comment"`

	UpdatedAt int64 `json:"updated_at"`
}

// TableLogUpdateRequest 更新现场数据
type TableLogUpdateRequest struct {
	Id int64 `json:"id"`

	OperatorId *int64 `json:"operator_id"`

	Type *int `json:"type"`

	TableName *string `json:"table_name"`

	Comment *string `json:"comment"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt *int64 `json:"updated_at"`
}

// TableLogListRequest 列表现场数据
type TableLogListRequest struct {
	Index int `json:"index"`
	Size  int `json:"size"`

	Id int64 `json:"id"`

	OperatorId *int64 `json:"operator_id"`

	Type *int `json:"type"`

	TableName *string `json:"table_name"`

	Comment *string `json:"comment"`

	UpdatedAt *int64 `json:"updated_at"`
}

// TableLogListResponse 列表回包数据
type TableLogListResponse struct {
	Total int             `json:"total"`
	List  []*TableLogInfo `json:"list"`
}

// TableLogInfoRequest 列表现场数据
type TableLogInfoRequest struct {
	Id int64 `json:"id"`

	OperatorId *int64 `json:"operator_id"`

	Type *int `json:"type"`

	TableName *string `json:"table_name"`

	Comment *string `json:"comment"`

	UpdatedAt *int64 `json:"updated_at"`
}

// TableLogInfo 详细数据
type TableLogInfo struct {
	Id int64 `json:"id"`

	OperatorId int64 `json:"operator_id"`

	Type int `json:"type"`

	TableName string `json:"table_name"`

	Comment string `json:"comment"`

	CreatedAt int64 `json:"created_at"`

	UpdatedAt int64 `json:"updated_at"`
}

// TableLogDeleteRequest 删除现场数据
type TableLogDeleteRequest struct {
	Id int64 `json:"id"`
}

// TableLogsEntityToDto entity数据转换
func TableLogsEntityToDto(tableLogs []*entity.TableLog) []*TableLogInfo {
	out := make([]*TableLogInfo, 0, len(tableLogs))
	for _, c := range tableLogs {
		out = append(out, TableLogEntityToDto(c))
	}
	return out
}

// TableLogEntityToDto entity数据转换
func TableLogEntityToDto(e *entity.TableLog) *TableLogInfo {
	create, _ := utils.TimeParse(e.CreatedAt)
	update, _ := utils.TimeParse(e.UpdatedAt)
	return &TableLogInfo{

		Id: e.Id,

		OperatorId: e.OperatorId,

		Type: e.Type,

		TableName: e.Table,

		Comment: e.Comment,

		CreatedAt: create.Unix(),

		UpdatedAt: update.Unix(),
	}
}
